home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / FilmPub.ifs < prev    next >
Text File  |  2005-04-10  |  5KB  |  199 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=Marek Pospisil, Kalten
  8. Title=Filmpub
  9. Description=Filmpub (CZ) import
  10. Site=http://filmpub.atlas.cz
  11. Language=CZ
  12. Version=1.0
  13. Requires=3.5.0
  14. Comments=
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program FilmPub;
  23.  
  24. const
  25.   BASEURL = 'http://filmpub.atlas.cz';
  26.  
  27.   // true ... bude vyplneno, false .. nebude vyplneno
  28.   cOriginalTitle   = true;
  29.   cTranslatedTitle = true;
  30.   cDirector        = false;
  31.   cCountry         = true;
  32.   cYear            = true;
  33.   cLength          = false;
  34.   cActors          = false;
  35.   cURL             = true;
  36.   cDescription     = true;
  37.   cComments        = true;
  38.  
  39. var
  40.   MovieName: string;
  41.   MovieURL: string;
  42.  
  43. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  44. var
  45.   i: Integer;
  46. begin
  47.   result := -1;
  48.   if StartAt < 0 then
  49.     StartAt := 0;
  50.   for i := StartAt to List.Count-1 do
  51.     if Pos(Pattern, List.GetString(i)) <> 0 then
  52.     begin
  53.       result := i;
  54.       Break;
  55.     end;
  56. end;
  57.  
  58. function iPos (Substr: String; S: String): Integer;
  59. begin
  60.   Substr := AnsiLowerCase(Substr);
  61.   S := AnsiLowerCase(S);
  62.   Result := Pos(Substr, S);
  63. end;
  64.  
  65. function FormatText(T: String): String;
  66. var BeginPos: Integer;
  67. begin
  68.   BeginPos := iPos('  ', T);
  69.   while (BeginPos > 0 ) do
  70.   begin
  71.     Delete(T, BeginPos, 1);
  72.     BeginPos := iPos('  ', T);
  73.   end;
  74.  
  75.   T := StringReplace(T, #13#10, '');
  76.   T := StringReplace(T, '</p>', #13#10#13#10);
  77.   T := StringReplace(T, '</P>', #13#10#13#10);
  78.   T := StringReplace(T, '<br>', #13#10);
  79.   T := StringReplace(T, '<BR>', #13#10);
  80.   Result := T;
  81. end;
  82.  
  83. (* ****************************************************************************
  84.  *
  85.  * FilmPub section
  86.  *
  87.  * ****************************************************************************)
  88. procedure AnalyzePageFilmPub(Address: string);
  89. var
  90.   Line, iLine, aLine, MovieTitle, MovieAddress: string;
  91.   BeginPos, EndPos: Integer;
  92. begin
  93.   Line := GetPage(Address);
  94.  
  95.   PickTreeClear;
  96.   PickTreeAdd('NalezenΘ filmy:', '');
  97.  
  98.   BeginPos := iPos('<a href="film.aspx', Line);
  99.  
  100.   while (BeginPos > 0 ) do
  101.   begin
  102.     Line := Copy(Line, BeginPos, Length(Line));
  103.  
  104.     EndPos := iPos('</a>', Line);
  105.     iLine := Copy(Line, 0, EndPos-1);
  106.     Line := Copy(Line, EndPos, Length(Line));
  107.  
  108.     BeginPos := iPos('"', iLine);
  109.     aLine := Copy(iLine, BeginPos+1, Length(iLine));
  110.     EndPos :=  iPos('"', aLine);
  111.     aLine := Copy(iLine, BeginPos+1, EndPos-1);
  112.     MovieAddress := BASEURL + '/' + aLine;
  113.     BeginPos := iPos('>', iLine);
  114.     MovieTitle := Trim(Copy(iLine, BeginPos+1, Length(iLine)));
  115.     PickTreeAdd(MovieTitle, MovieAddress);
  116.  
  117.     BeginPos := iPos('<a href="film.aspx', Line);
  118.   end;
  119.     if PickTreeExec(Address) then
  120.       AnalyzeMoviePageFilmPub(Address);
  121. end;
  122.  
  123.  
  124. procedure AnalyzeMoviePageFilmPub(Address: string);
  125. var
  126.   Line, iLine, aLine, Value, MovieAddress: string;
  127.   BeginPos, EndPos, tPos: Integer;
  128. begin
  129.   Line := GetPage(Address);
  130.   
  131.   BeginPos := iPos('Detail filmu', Line);
  132.   Line := Copy(Line, BeginPos, Length(Line));
  133.   
  134.   BeginPos := iPos('<h1>', Line);
  135.   EndPos := iPos('</h1>', Line);
  136.   iLine := Copy(Line, BeginPos, EndPos-BeginPos);
  137.   EndPos := iPos('<span>', iLine);
  138.   Value := Copy(iLine, 0, EndPos-1);
  139.   HTMLRemoveTags(Value);
  140.   HTMLDecode(Value);
  141.   if cTranslatedTitle then
  142.     SetField(fieldTranslatedTitle, Value);
  143.  
  144.   Value := Copy(iLine, EndPos, Length(iLine));
  145.   HTMLRemoveTags(Value);
  146.   HTMLDecode(Value);
  147.   if cOriginalTitle then
  148.     SetField(fieldOriginalTitle, Value);
  149.  
  150.   BeginPos := iPos('clanek.aspx?articleId=', Line);
  151.   Line := Copy(Line, BeginPos, Length(Line));
  152.   EndPos := iPos('"', Line);
  153.   MovieAddress := Copy(Line, 0, EndPos-1);
  154.  
  155.  
  156.   Line := GetPage(BASEURL + '/' + MovieAddress);
  157.   BeginPos := iPos('<p class="prolog"', Line);
  158.   Line := Copy(Line, BeginPos, Length(Line));
  159.   EndPos := iPos('</p>', Line);
  160.   Value := Copy(Line, 0, EndPos-1);
  161.   Value := FormatText(Value);
  162.   HTMLRemoveTags(Value);
  163.   HTMLDecode(Value);
  164.   if cDescription then
  165.     SetField(fieldDescription, Value);
  166.  
  167.   Line := Copy(Line, EndPos+Length('</p>'), Length(Line));
  168.   EndPos := iPos('</div>', Line);
  169.   Value := Copy(Line, 0, EndPos-1);
  170.  
  171.   Value := FormatText(Value);
  172.   HTMLRemoveTags(Value);
  173.   HTMLDecode(Value);
  174.   if cComments then
  175.     SetField(fieldComments, Value);
  176.   
  177.  if cURL then
  178.     SetField(fieldURL, BASEURL + '/' + MovieAddress);
  179.  
  180.   //DisplayResults;
  181. end;
  182.  
  183.  
  184. begin
  185.   if CheckVersion(3,5,0) then
  186.   begin
  187.     MovieName := GetField(fieldTranslatedTitle);
  188.     if MovieName = '' then
  189.       MovieName := GetField(fieldOriginalTitle);
  190.     if Input('FilmPub Import', 'Enter the title of the movie:', MovieName) then
  191.     begin
  192.       AnalyzePageFilmPub(BASEURL+'/hledej.aspx?findString='+UrlEncode(MovieName));
  193.     end;
  194.   end
  195.   else
  196.   ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  197. end.
  198.  
  199.